package com.mlick.a.leetcode;


import cn.leetcode.base.ListNode;

/**
 * 反转链表
 * https://leetcode.cn/problems/reverse-linked-list/description/
 */
public class LC206 {


    /**
     * 思路： 双指针操作
     */
    static class Solution {
        public ListNode reverseList(ListNode head) {
            ListNode cur = head, pre = null;

            while (cur != null) {
                ListNode temp = cur.next; // 暂存下一个节点的值
                cur.next = pre; // 将next引用指向为pre
                pre = cur; // pre 暂存至 cur
                cur = temp; // 访问下一个节点

            }
            return pre;
        }
    }
}
